#include <iostream>

#include <QVector3D>
#include <QTextStream>

#include "DlgRawData.h"

DlgRawData::DlgRawData(QWidget *parent)
: QDialog(parent)
{
	setupUi(this);
}

static QString fmt(double f)
{
	QString ret;
	QTextStream ts(&ret, QIODevice::WriteOnly);
	ts.setNumberFlags(QTextStream::ForceSign);
	ts.setFieldWidth(5);
	ts.setRealNumberPrecision(3);
	ts.setRealNumberNotation(QTextStream::FixedNotation);
	ts << f;
	return ret;
}

void DlgRawData::updateBox(const QString &pfx, const QVector3D &vec)
{
	findChild<QLabel *>(pfx + "XTL")->setText(fmt(vec.x()));
	findChild<QLabel *>(pfx + "YTL")->setText(fmt(vec.y()));
	findChild<QLabel *>(pfx + "ZTL")->setText(fmt(vec.z()));
	findChild<RenderArea *>(pfx + "XRA")->setValue(vec.x());
	findChild<RenderArea *>(pfx + "YRA")->setValue(vec.y());
	findChild<RenderArea *>(pfx + "ZRA")->setValue(vec.z());
}

void DlgRawData::update(const QVector3D &gyr, const QVector3D &acc, const QVector3D &mag)
{
	updateBox("gyr", gyr);
	updateBox("acc", acc);
	updateBox("mag", mag);
}

